package com.project.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;

public class InputServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置请求信息编码集
        req.setCharacterEncoding("utf-8");
        //设置响应信息编码集
        resp.setContentType("text/html;charset=utf-8");

        //得到表单数据
        String name = req.getParameter("name");
        String sex = req.getParameter("sex");
        String edu = req.getParameter("edu");
        String birthday = req.getParameter("birthday");

        //得到多个同名键值对的值，返回数组
        String[] likes = req.getParameterValues("like");

        String str = req.getParameter("like");
        resp.getWriter().print("姓名："+name+"  性别："+sex+"   学历："+edu+"  生日："+birthday
                +"   爱好："+ Arrays.toString(likes)+"  -----"+str);
    }
}
